﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System;
using System.Windows;
using Majesty_of_Omega.Logic.GameConfiguration;

#endregion

namespace Majesty_of_Omega.GUI.Pages.Setup.Parts
{
    /// <summary>
    /// Interaction logic for SetupTitle.xaml
    /// </summary>
    public partial class SetupTitlePart
    {
        /// <summary>
        /// Constructor of the setup title part
        /// </summary>
        public SetupTitlePart()
        {
            InitializeComponent();
            GameConfigurator.GameSettings.OnRaceChanged += GameSettings_OnRaceChanged;
        }

        private void GameSettings_OnRaceChanged(object sender, EventArgs e)
        {
            CreateTitleText();
        }

        private void CreateTitleText()
        {
            TitleText.Text = TitleString + ":  " + GameConfigurator.GameSettings.SelectedRace.Name;
        }

        /// <summary>
        /// Titlestring
        /// </summary>
        public string TitleString
        {
            get { return (string) GetValue(TitleStringProperty); }
            set { SetValue(TitleStringProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for TitleString.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty TitleStringProperty =
            DependencyProperty.Register("TitleString", typeof (string), typeof (SetupTitlePart),
                                        new PropertyMetadata("(title not set", OnTitleChanged));

        private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            SetupTitlePart setupTitlePart = (SetupTitlePart) d;
            setupTitlePart.CreateTitleText();
        }
    }
}